<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<button onclick="btn()">按钮</button>
<script>
  let getTime = sessionStorage.getItem('getTime');
  console.log(getTime);
  // let getTime = new Date().getTime();
  // let getwei = 1000 * 60 * 60 + 2000;
  // console.log(getTime);
  // let times = getwei - getTime;

  function btn(){
    payQrTime();
    // if (getwei > 0){
    //   let that = this;
    //   let setInter = setInterval(function () {
    //     let surplusH = Math.floor(getwei / (1000 * 60 * 60) % 60);  // 计算小时数
    //     let surplusM = Math.floor(getwei / (1000 * 60) % 60);  // 计算分钟数
    //     let surplusS = Math.floor(getwei / 1000 % 60);  // 计算秒数
    //     getwei = getwei - 1000;
    //     console.log(`${surplusH}小时${surplusM}分钟${surplusS}秒`);
    //     if (getwei <= 0) {
    //       clearInterval(setInter);
    //     }
    //   }, 1000)
    // }
  }
  function payQrTime(){
    // let weiPayTiem = 1588232422663 - new Date().getTime();
    // let weiPayTiem = 1000 * 60 * 60 * 2
    let wei = Math.floor(1588234523324/1000);
    console.log(wei);
    let nown = Math.floor(1588227321449/1000);
    console.log(nown);
    let weiPayTiem = wei - nown
    let that = this;
    let payTimeText = null;
    if (weiPayTiem > 0) {
      let payInvert = setInterval(function () {
        // let surplusH = Math.floor(weiPayTiem / (1000 * 60 * 60) % 60);  // 计算小时数
        // let surplusM = Math.floor(weiPayTiem / (1000 * 60) % 60);  // 计算分钟数
        // let surplusS = Math.floor(weiPayTiem / 1000 % 60);  // 计算秒数
        let surplusH = Math.floor(weiPayTiem / ( 60 * 60) % 60);  // 计算小时数
        let surplusM = Math.floor(weiPayTiem / 60 % 60);  // 计算分钟数
        let surplusS = Math.floor(weiPayTiem % 60);  // 计算秒数
        if (surplusH > 0 && surplusM > 0) {
          payTimeText = `${surplusH}小时${surplusM}分${surplusS}秒`;
        } else if (surplusH > 0 && surplusM <= 0) {
          payTimeText = `${surplusH}小时${surplusS}秒`;
        } else if (surplusH <= 0 && surplusM > 0) {
          payTimeText = `${surplusM}分${surplusS}秒`;
        } else if (surplusH <= 0 && surplusM <= 0) {
          payTimeText = `${surplusS}秒`;
        }
        console.log(payTimeText);
        weiPayTiem = weiPayTiem - 1;
        if (weiPayTiem < 0) {
          clearInterval(payInvert);
        }
      }, 1000)
    }
  }
</script>
</body>
</html>